//
//  FSPSJOpinionViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/11.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSPSJOpinionViewController.h"

@interface FSPSJOpinionViewController ()
//局领导审批
@property (weak, nonatomic) IBOutlet UITextField *BureauTextField;

//责任人
@property (weak, nonatomic) IBOutlet UITextField *responsibleTextField;

//日期
@property (weak, nonatomic) IBOutlet UITextField *dateTextField;

//分管局长意见
@property (weak, nonatomic) IBOutlet UITextField *chargeBureauTextField;

//分管责任人
@property (weak, nonatomic) IBOutlet UITextField *chargeResponsibleTextField;

//分管日期
@property (weak, nonatomic) IBOutlet UITextField *chargeDateTextField;

//科室意见
@property (weak, nonatomic) IBOutlet UITextField *SectionsTextField;

//科室负责人
@property (weak, nonatomic) IBOutlet UITextField *sectionsResponsibleTextField;

//科室日期
@property (weak, nonatomic) IBOutlet UITextField *sectionsDate;



@end

@implementation FSPSJOpinionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setRightItem];
    
}

-(void)setRightItem{
    
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(submitAction)];
    
    self.navigationItem.rightBarButtonItem = rightItem;
}

-(void)submitAction{
    [self.view endEditing:YES];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    if (self.BureauTextField.text.length !=0) {
        [dict setObject:self.BureauTextField.text forKey:@"JuLingdaoText"];
    }
    
    if (self.responsibleTextField.text.length !=0) {
        [dict setObject:self.responsibleTextField.text forKey:@"ZeRenRenText"];
    }
    
    if (self.dateTextField.text.length !=0) {
        [dict setObject:self.dateTextField.text forKey:@"dateText"];
    }
    
    if (self.chargeBureauTextField.text.length !=0) {
        [dict setObject:self.chargeBureauTextField.text forKey:@"FenGuanJuZhangText"];
    }
    
    if (self.chargeResponsibleTextField.text.length !=0) {
        [dict setObject:self.chargeBureauTextField.text forKey:@"FenGuanZeRenRen"];
    }
    
    if (self.chargeDateTextField.text.length !=0) {
        [dict setObject:self.chargeDateTextField.text forKey:@"FenGuanDate"];
    }
    
    if (self.SectionsTextField.text.length !=0) {
        [dict setObject:self.SectionsTextField.text forKey:@"KeShiText"];
    }
    
    if (self.sectionsResponsibleTextField.text.length !=0) {
        [dict setObject:self.sectionsResponsibleTextField.text forKey:@"KeShiFuZeRen"];
    }
    
    if (self.sectionsDate.text.length !=0) {
        [dict setObject:self.sectionsDate.text forKey:@"KeShiDates"];
    }
    
    
    
    
    NSData * data  = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
    NSString * infoString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array =@[@{@"userId":userId},@{@"unid":self.identifier},@{@"formxml":infoString}];
//批事件提交
    [HttpTools requestWithURL:KexchexchangeURL arrays:array method:KSetSubmitInstructions success:^(id JSON) {
        [self.view.window makeToast:@"提交意见成功"];
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        [self.view.window makeToast:@"提交意见失败"];
    }];
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    
    return YES;
}




@end












